<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>部门信息</title>

<link rel="shortcut icon"
	href="<c:url value="/easyui/css/images/favicon.ico"/>" />
<link rel="stylesheet" href="<c:url value="/css/flipclock.css"/>">
<link href="<c:url value="/css/CalcSS3.css"/>" rel="stylesheet"
	type="text/css" />
<link href="<c:url value="/css/index.css"/>" rel="stylesheet"
	type="text/css" />
<link href="<c:url value="/easyui/css/easyui.css"/>" rel="stylesheet"
	type="text/css">
<link href="<c:url value="/easyui/css/easyui_animation.css"/>"
	rel="stylesheet" type="text/css">

<link href="<c:url value="/easyui/css/easyui_plus.css" />"
	rel="stylesheet" type="text/css">
<link href="<c:url value="/easyui/css/insdep_theme_default.css" />"
	rel="stylesheet" type="text/css">
<link href="<c:url value="/easyui/css/icon.css" />" rel="stylesheet"
	type="text/css">
<link
	href="<c:url value="/easyui/css/font-awesome-4.7.0/css/font-awesome.min.css" />"
	rel="stylesheet" type="text/css">
<!-- 引入 ECharts 文件 -->
<script type="text/javascript" src="<c:url value="/js/echarts.js"/>"></script>
<!--放入自定义的图表-->

<script type="text/javascript" src="<c:url value="/js/monitor.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.min.js"/>"></script>
<%--<script type="text/javascript" src="js/jquery.js"></script>--%>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/easyui/js/jquery.insdep-extend.min.js"/>">
	
</script>
<style type="text/css">
.by {
	padding: 10px;
}

.line {
	margin-top: 10px;
}
</style>
</head>
<body>


<script type="text/javascript">
	var DeptButtons = function(crmDeptno) {
		var DeptDetailBtn = "";

		DeptDetailBtn = " <a class='easyui-linkbutton' onclick='DeptDetail("
				+ crmDeptno + ")'>部门详情</a>";
		return DeptDetailBtn;
	};
	$(function() {
		$("#append-dept").linkbutton({
			onClick : function() {
				$("#yk-add-dept").window("open");
			}
		});
		$("#modify-dept").linkbutton({
			onClick : function() {
				var row = $("#yk-crm-dept").datagrid("getSelected");
				if (row) {
					$("#yk-update-dept").window("open");
				} else {
					$.messager.alert("提示", "请选择要修改的行！");
				}
			}
		});

		$("#all-dept").linkbutton({
			onClick : function() {
				$("#yk-crm-dept").datagrid({
					url : "queryAllPage",
					method : "post"
				});
				$("#yk-crm-dept").datagrid("reload");

			}
		});

		$("#deleting-dept").linkbutton({
			onClick : function() {
				var row = $("#yk-crm-dept").datagrid("getSelected");
				if (row) {
					$.messager.confirm("询问", "确定要删除吗？", function(v) {
						if (v) {
							$.post("deleting-dept", {
								crmDeptno : row.crmDeptno
							}, function(r) {
								if (r.success) {
									$("#yk-crm-dept").datagrid("reload");
									$.messager.alert("提示", "删除成功！");
								} else {
									$.messager.alert("提示", r.message);

								}
							});
						}
					});
				} else {
					$.messager.alert("提示", "请选择要删除的行！");
				}
			}
		});

		
		$("#yk-crm-dept").datagrid({
	         onBeforeSelect: function(index,row){
	             var row =$("#yk-crm-dept").datagrid("getSelected");
	             var curRowindex = $("#yk-crm-dept").datagrid("getRowIndex",row);
	             if(curRowindex != index) {return true;}
	             else{ $("#yk-crm-dept").datagrid("unselectRow",index); return false;}
	         } 
		 });
	});
</script>
	<table id="yk-crm-dept" class="easyui-datagrid"
		data-options="
	       fit:true,fitColumns:true, autoRowHeight:true,nowrap:false,rownumbers:true,
	           striped:true,singleSelect:true,toolbar:'#yk-dept-control',pagination:true,
	           url:'queryAllPage',method:'post',pageList:[5,10,15,20],pageSize:10
	       ">
		<thead>
			<tr>
				<th data-options="field:'checkbox',checkbox:true,width:20"></th>
				<th data-options="field:'crmDeptno',width:3">部门ID</th>
				<th data-options="field:'crmDname',width:7">部门名称</th>
<!--                 <th data-options="field:'other',width:3, formatter: function(value,row,index){ -->
<!-- 					return DeptButtons(row.roleId); -->
<!-- 				}">操作</th> -->
			</tr>
		</thead>
		<tbody>


		</tbody>
	</table>
	<div id="yk-dept-control">
		<span><a id="append-dept" class="easyui-linkbutton"
			data-options="iconCls:'icon-add'">添加部门</a> </span> <span><a
			id="modify-dept" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit'">修改部门信息</a> </span> <span><a
			id="deleting-dept" class="easyui-linkbutton"
			data-options="iconCls:'icon-remove'">删除部门</a> </span> <span><a
			id="all-dept" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload'">显示所有部门</a> </span> <span><input
			id="query-dept" class="easyui-searchbox"
			data-options="label:'搜索:',prompt:'请输入部门名称',width:300,
			    searcher:function(value,name){
			        $('#yk-crm-dept').datagrid({
			           url:'query-Some-CrmDepts',
			           method:'post',
			           queryParams:{crmDname:value}
			        });
			         $('#yk-crm-dept').datagrid('reload');
			         $('#query-dept').searchbox('clear');
			    }
			" />
		</span>
	</div>
	<div id="yk-update-dept" class="easyui-dialog"
		data-options="title:'修改部门信息',width:500,height:200,closed:true,
	     href:'update-dept',method:'get',bodyCls:'by',buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				   $('#fm').form({
				      onSubmit:function(params){
				          return $(this).form('validate');
				      },
				      success:function(v){
				         v = eval('(' + v + ')');
				         if(v.success){
				            $('#yk-update-dept').window('close');
				            $('#yk-crm-dept').datagrid('reload');
				            $.messager.alert('提示', '修改成功！');
				         }else{
				            $('#yk-update-dept').window('close');
				            $.messager.alert('提示', v.message);
				       }  
				      }
				   }).submit();
				}
					
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#yk-update-dept').window('close');
				}
			}],
			onLoad:function(){
			  var rows = $('#yk-crm-dept').datagrid('getSelected');
			  var crmDeptno = rows.crmDeptno;
			  $('#fm').form('load','init?crmDeptno='+crmDeptno);
			},
			onOpen:function(){
			  var rows = $('#yk-crm-dept').datagrid('getSelected');
			  var crmDeptno = rows.crmDeptno;
			  $('#fm').form('load','init?crmDeptno='+crmDeptno);
			}
			
	     "></div>

	<div id="yk-add-dept" class="easyui-dialog"
		data-options="title:'添加部门',width:500,height:200,closed:true,
	     href:'to-add-dept',method:'get',bodyCls:'by',buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				   $('#f').form({
				      onSubmit:function(params){
				          return $(this).form('validate');
				      },
				      success:function(v){
				        v = eval('(' + v + ')');
				        if(v.success){
				           $('#yk-add-dept').window('close');
				           $('#yk-crm-dept').datagrid('reload');
				           $.messager.alert('提示', '添加成功！');
				         }else{
				           $('#yk-add-dept').window('close');
				           $.messager.alert('提示', v.message);
				       }  
				      }
				   }).submit();
				}
					
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#yk-add-dept').window('close');
				}
			}],
			onOpen:function(){
			   $('#f').form('clear')
			}
	     ">
	</div>
</body>
</html>